var express = require('express');
var router = express.Router();
var core = require('core');
var api = core.api;
var wechat = core.wechat;
var wapi = wechat.api;

router.get('/', function(req, res, next){
    var next_openid = null;
    var length = 1000;

    getList = function(){
        var param = {
            "access_token" : core.wechat.config.accessToken
        };
        // if(next_openid)
            // param.next_openid = next_openid;
        wapi.list.user.getList(param, function(err, list){
            var x = 0;

            var time = setInterval(function(){

                api.list.user.reg({openid: list.data.openid[x]});

                wechat.length = x += 1;
                if(x === list.count){
                    clearInterval(time);
                    res.send('写成功:'+x);
                }
            },50);

        });
    };

    getList();
});

module.exports = router;
